window.onload = main;

import { Triangle } from "./geom/Triangle";
import { Point } from "./geom/Point";

// import Triangle = terr

// import Sprite = Laya.Sprite;

// var triangleBase: Triangle = { p0: { x: 0, y: 0 }, p1: { x: -1, y: -1 }, p2: { x: 1, y: -1 } };
var triangleBase = new Triangle(new Point(0, 0), new Point(1, 0), new Point(0, 1));

function main()
{
    var width = 500;
    var height = 400;

    var canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = '#ffffff';
    ctx.fillRect(0, 0, width, height);

    canvas.addEventListener("mousedown", function (event: MouseEvent): void
    {
        console.log(event.clientX, event.clientY);
        console.log(event.layerX, event.layerY);
    });



    drawTriangle(ctx, triangleBase);

    document.body.appendChild(canvas);
}

function drawTriangle(ctx: CanvasRenderingContext2D, triangle: Triangle)
{
    var p0 = triangle.p0

    ctx.beginPath();
    ctx.moveTo(triangle.p0.x * 100, triangle.p0.y * 100);
    ctx.lineTo(triangle.p1.x * 100, triangle.p1.y * 100);
    ctx.lineTo(triangle.p2.x * 100, triangle.p2.y * 100);
    ctx.stroke();
}

function transform(p: { x: number, y: number })
{

}